using System;
using System.Collections.Generic;
using System.Text;
using QuanLySim.DTO;
using System.Data;

namespace QuanLySim.DAO
{
    class clsTimKiemDAO
    {
        #region variable
        private string m_strError;
        private clsCommand m_Command;
        #endregion

        #region property
        public string ERORR
        {
            get { return m_strError; }
            set { m_strError = value; }
        }
        #endregion

        #region "method"
        public clsTimKiemDAO()
        {
            m_strError = "";
            m_Command = new clsCommand();
        }

        public DataTable TenGoi()
        {
            m_Command = new clsCommand();
            DataTable table = new DataTable();
            string strSelect = "SELECT TENGOI FROM TENSIM";
            if (m_Command.Connect())
            {
                table = m_Command.Select(strSelect);
                m_Command.CloseConnect();
                return table;
            }
            m_strError = m_Command.ERORR;
            return null;
        }

        public DataTable TimKiem(clsTimKiemDTO TimKiemDto)
        {
            m_Command = new clsCommand();
            DataTable table = new DataTable();
            string strSelect = "SELECT SODIENTHOAI, TENMANG, GIATRI, TENGOI FROM SIM, DAUSO, TENSIM";
            strSelect += " WHERE DAUSO.DAUSO = SIM.DAUSO AND SIM.MATEN = TENSIM.MATEN";
            strSelect += " AND TENMANG = '" + TimKiemDto.TENMANG + "'";
            if (TimKiemDto.SODIENTHOAI != "")
            {
                strSelect += " AND SODIENTHOAI = '" + TimKiemDto.SODIENTHOAI + "'";
            }
            if (TimKiemDto.DAUSO != "")
            {
                strSelect += " AND DAUSO.DAUSO = '" + TimKiemDto.DAUSO + "'";
            }
            if (TimKiemDto.GIA != "")
            {
                strSelect += " AND GIATRI = '" + TimKiemDto.GIA + "'";
            }
            if (TimKiemDto.TENGOI != "")
            {
                strSelect += " AND TENGOI = '" + TimKiemDto.TENGOI + "'";
            }
            if (TimKiemDto.LOAISIM != "")
            {
                strSelect += " AND LOAISIM = '" + TimKiemDto.LOAISIM + "'";
            }

            if (m_Command.Connect())
            {
                table = m_Command.Select(strSelect);
                m_Command.CloseConnect();
                return table;
            }
            m_strError = m_Command.ERORR;
            return null;
        }
        #endregion
    }
}
